<?php 
use Managers\Passport;
class App_Plugin_SearchWidget extends Zend_Controller_Plugin_Abstract{
	public static $VISIBLE = true;
    /**
     * Function description
     * 
     * @since 28 мая 2010
     * @author diotheos
     * @return void
     */
    public function postDispatch(){
    	if(self::$VISIBLE){
            $form = new App_Form_Car_Search();
           
            $stateManager = new \Managers\State();
            $states = $stateManager->get(null);
            Lib_Utility::createDefaultMultiOption($form, $form->getSubForm('placement')->getSubForm('0')->getElement('state'));
            Lib_Utility::createMultiOptions($form, $form->getSubForm('placement')->getSubForm('0')->getElement('state'), $states);
            unset($states, $stateManager);


            $yearSetFrom = Lib_Utility::getRangeObjectSet(1980, date('Y'));
            Lib_Utility::createDefaultMultiOption($form,$form->getSubForm('years')->getElement('from'),null, 'От');
            Lib_Utility::createMultiOptions($form,$form->getSubForm('years')->getElement('from'),$yearSetFrom);
            unset($yearSetFrom);

            $yearSetTo = Lib_Utility::getRangeObjectSet(date('Y'), 1980);
            Lib_Utility::createDefaultMultiOption($form,$form->getSubForm('years')->getElement('to'),null, 'До');
            Lib_Utility::createMultiOptions($form,$form->getSubForm('years')->getElement('to'),$yearSetTo);
            unset($yearSetTo);

            Lib_Utility::createDefaultMultiOption($form, $form->getSubForm('placement')->getSubForm('0')->getElement('city'));

            $markManager = new \Managers\Mark();
            $marks = $markManager->get(null);
            Lib_Utility::createDefaultMultiOption($form,$form->getSubForm('general')->getSubForm('0')->getElement('marks'));
            Lib_Utility::createMultiOptions($form,$form->getSubForm('general')->getSubForm('0')->getElement('marks'),$marks);
            unset($marks, $markManager);

            Lib_Utility::createDefaultMultiOption($form,$form->getSubForm('general')->getSubForm('0')->getElement('models'));

            $bodyManager = new \Managers\Subcategory();
            $bodies = $bodyManager->get(null);
            Lib_Utility::createDefaultMultiOption($form,$form->getElement('body'));
            Lib_Utility::createMultiOptions($form,$form->getElement('body'),$bodies);
            unset($bodies, $bodyManager);

            $colorManager = new \Managers\Color();
            $colors = $colorManager->get(null);
            Lib_Utility::createDefaultMultiOption($form,$form->getElement('color'));
            Lib_Utility::createMultiOptions($form,$form->getElement('color'),$colors);
            unset ($colors, $colorManager);

            $gearManager = new \Managers\Gearbox();
            $gears = $gearManager->get(null);
            Lib_Utility::createDefaultMultiOption($form,$form->getElement('gear'));
            Lib_Utility::createMultiOptions($form,$form->getElement('gear'),$gears);
            unset ($gears, $gearManager);

            $fuelManager = new \Managers\Fuel();
            $fuels = $fuelManager->get(null);
            Lib_Utility::createDefaultMultiOption($form,$form->getElement('fuel'));
            Lib_Utility::createMultiOptions($form,$form->getElement('fuel'),$fuels);
            unset($fuels, $fuelManager);

            $exchangeManager = new \Managers\ExchangeType();
            $exchange = $exchangeManager->get(null);
            Lib_Utility::createDefaultMultiOption($form,$form->getElement('exchange'));
            Lib_Utility::createMultiOptions($form,$form->getElement('exchange'),$exchange);
            unset($exchange, $exchangeManager);
            
            $credit = array(
                array('id'=>-1,'name' => _('Все')),
                array('id'=>1,'name' => _('Только кредитные')),
                array('id'=>0,'name' => _('Только без кредита'))
            );
            $credit = Lib_Utility::createObjectSet($credit);
            Lib_Utility::createMultiOptions($form,$form->getElement('credit'),$credit);
            unset($credit);

            $damage = array(
                array('id'=>-1,'name' => _('Все')),
                array('id'=>1,'name' => _('Только битые')),
                array('id'=>0,'name' => _('Только небитые'))
            );
            $damage = Lib_Utility::createObjectSet($damage);
            Lib_Utility::createMultiOptions($form,$form->getElement('damage'),$damage);
            unset ($damage);

            $custom = array(
                array('id'=>-1,'name' => _('Все')),
                array('id'=>1,'name' => _('Только растаможенные')),
                array('id'=>0,'name' => _('Только нерастаможенные'))
            );
            $custom = Lib_Utility::createObjectSet($custom);
            Lib_Utility::createMultiOptions($form,$form->getElement('custom'),$custom);
            unset($custom);

            $layout = Zend_Layout::getMvcInstance();
            $layout->assign('searchFormClear', $form);
            $layout->assign('searchForm', $form);
	   }
    }
}